<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>共享车位</title>
    <link rel="stylesheet" href="mobile/layui/css/layui.mobile.css">
    <link rel="stylesheet" href="mobile/layui/css/layui.css">
    <link rel="stylesheet" href="mobile/css/yj_css.css">
    <link rel="stylesheet" href="mobile/css/iphoneX.css">
</head>
<body>
<header class="yj-header">
    <a class="yj-header-return layui-icon"></a>
    <span>首页</span>
    <a class="yj-header-meau"></a>
</header>
<footer class="yj-footer">
    <a class="yj-footer-item">
        <span class="yj-footer-icon"><img src="mobile/images/home2.png"></span>
        <p class="yj-footer-title yj-color-main">首页</p>
    </a>
    <a class="yj-footer-item yj-footer-middle" href="lessorinfo">
        <span class="yj-footer-icon"><img src="mobile/images/user1.png"></span>
        <p class="yj-footer-title">个人中心</p>
    </a>
    <a class="yj-footer-item" href="lessororder">
        <span class="yj-footer-icon"><img src="mobile/images/printer1.png"></span>
        <p class="yj-footer-title">订单详情</p>
    </a>
</footer>
<div class="yj-content">
    <!-- banner -->
    <link rel="stylesheet" href="mobile/css/swiper.min.css">

    <div class="yj-mar-t yj-bgfff" style="height: 80px;line-height: 80px;">
        <ul class="yj-user-row">
            <li class="yj-border-r yj-user-row-item">
                <span style="font-size: 20px;font-family: '微软雅黑', '宋体'">车位数量：</span>
                <span id="carparknumber" style="font-size: 16px">0</span>
            </li>
            <li class="yj-user-row-item">
                <span style="font-size: 20px;font-family: '微软雅黑', '宋体'">昨日流水：</span>
                <span id="income" style="font-size: 16px">0</span>
            </li>
        </ul>
    </div>
    <div class="yj-mar-t yj-bgfff">
        <ul class="yj-order yj-pad-t" id="carParkContent">
        </ul>
    </div>

    <div class="yj-mar-t yj-bgfff" style="text-align: center">
        <p><a href="javascript:authroized()"><img src="mobile/images/plus-circle.png" width="100px" height="100px"></a>
        </p>
        <p>添加车位</p>
    </div>


</div>
<script th:src="@{/mobile/js/jquery.min.js}"></script>
<script src="mobile/layui/layui.js"></script>
<script th:inline="javascript">
    var url = [[@{
        /}]];
        layui.use("layer", function () {
            var layer = layui.layer;
        });
</script>
<script>
    $(document).ready(function () {
        $.ajax({
            url: url + "lessor/mycarpark",
            success: function (result) {
                var content = $("#carParkContent").text("");
                $("#carparknumber").text(result.result.length);
                for (var i = 0; i < result.result.length; i++) {
                    var carPark = result.result[i];
                    var state = carPark.cStatus;
                    var operate = "";
                    if (state === "通过") {
                        state = carPark.cState;
                        if (state === "下架") {
                            operate = "<p class=\"yj-list-item yj-pad-lr yj-border-t\"><span class=\"yj-right\"><a class=\"yj-btn yj-btn-sm\" href=\"javascript:up(" + carPark.id + ")\">上架</a></span></p>"
                        } else if (state === "未租") {
                            operate = "<p class=\"yj-list-item yj-pad-lr yj-border-t\"><span class=\"yj-right\"><a class=\"yj-btn yj-btn-sm\" href=\"javascript:down(" + carPark.id + ")\">下架</a></span></p>"
                        }

                    }
                    var carinfo = "<li class=\"yj-order-item yj-bgfff yj-mar-t yj-pad-lr-big\">" +
                        "<p class=\"yj-list-item\" style='height: auto;line-height: 100%'><img class=\"yj-list-item-icon yj-left\" src=\"mobile/images/local.png\"><span class='yj-left' style='width: 80%;overflow: hidden;'>"+ carPark.community.comAddress + carPark.community.comName + " : " + carPark.cNumber + "号车位</span><span class=\"yj-color-red yj-right\">" + state + "</span></p>" +
                        "<a class=\"yj-order-basicinfo yj-pad-tb-big\">" +
                        "<span class=\"yj-goods-thumbnail\"><img src=\"/sharepark/upload/" + carPark.cPic + "\"></span>" +
                        "<div class=\"yj-confirm-goods-textinfo\">" +
                        "<div class=\"yj-goods-price yj-pad-t yj-clearfix\">" +
                        "<span>     " + carPark.cPrice + " / 时</span>" +
                        "<p class=\"yj-color-gray yj-mar-tb\">    " + carPark.cAddress + "</p></div></div></a>" + operate + "</li>"
                    content.append(carinfo);
                }
            }
        })
    });

    $(document).ready(function () {
        $.ajax({
            url: "lessor/income",
            success: function (data) {
                if(data.result){
                    $("#income").text(data.result);
                }
            }
        })
    })

    function up(id) {
        $.ajax({
            url: "lessor/upcarpark",
            data: {id: id},
            success: function (data) {
                alert(data.msg);
                if (data.code == 200) {
                    window.location.href = "/sharepark/lessorindex";
                }
            }
        })
    }

    function down(id) {
        $.ajax({
            url: "lessor/downcarpark",
            data: {id: id},
            success: function (data) {
                alert(data.msg);
                if (data.code == 200) {
                    window.location.href = "/sharepark/lessorindex";
                }
            }
        })
    }

    function authroized() {
        $.ajax({
            url: "userInfo/activeUserInfo",
            type: "post",
            success: function (data) {
                if (data.uCard == null) {
                    alert("请先实名认证");
                    window.location.href = "/sharepark/user/authentication";
                } else {
                    window.location.href = "/sharepark/addcarpark";
                }
            }
        })
    }
</script>

</body>

</html>